package edu.fim.presentation.view.model;

import java.util.Calendar;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import edu.fim.presentation.model.bean.Portion;

public class ScheduleTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 9096955106053980225L;

	private String[] columnNames;
	private List<Portion> portions;

	public ScheduleTableModel(List<Portion> portions) {
		this.columnNames = new String[] { "Food", "Amount", "Time" };
		this.portions = portions;
	}

	public List<Portion> getPortions() {
		return portions;
	}

	public void setPortions(List<Portion> portions) {
		this.portions = portions;
	}

	@Override
	public String getColumnName(int column) {
		return columnNames[column];
	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return portions.size();
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		Portion portion = portions.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return portion.getFood().getName();
		case 1:
			return portion.getFoodAmount();
		case 2:
			return portion.getMeal().getDate().get(Calendar.HOUR) + ":" + portion.getMeal().getDate().get(Calendar.MINUTE);
		}
		return null;
	}
}
